//
//  XGL_MessageChatTextTableViewCell.swift
//  XGamesLive
//
//  Created by ios on 2024/5/28.
//

import UIKit

class XGL_MessageChatTextTableViewCell: UITableViewCell {
    
    var userHeader: UIImageView!
    var chatTextView: PanPaddingLabel!
    
    var itemData: XGL_MessageChatData = XGL_MessageChatData(){
        didSet{
            self.userHeader.loadImageWithUrl(itemData.header)
            self.chatTextView.text = itemData.content
        }
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        self.layoutIfNeeded()
        self.chatTextView.addCorner(conrners: [.topLeft,.topRight,.bottomLeft], radius: 8.0)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.contentView.backgroundColor = .clear
        self.backgroundColor = .clear
        self.selectionStyle = .none
        self.creatItemView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func creatItemView(){
        self.userHeader = UIImageView().then({ make in
            make.backgroundColor = UIColor.hexColor("#F4F8FB")
            make.layerCornerRadius = 20.0
            make.clipsToBounds = true
        })
        self.chatTextView = PanPaddingLabel().then({ make in
            make.textColor = UIColor.hexColor("#191A1D")
            make.font = UIFont.pingfangSC_Regular(fontSize: 14.0)
            make.layerCornerRadius = 2.0
            make.numberOfLines = 0
            make.lineBreakMode = .byWordWrapping
            make.backgroundColor = UIColor.hexColor("#80FFE6")
            make.textInsets = UIEdgeInsets(top: 8, left: 10, bottom: 8, right: 10)
            make.setContentHuggingPriority(700, for: .horizontal)
            make.setContentCompressionResistancePriority(680, for: .horizontal)
        })
        let line = UIView()
        self.contentView.addSubviews([self.userHeader,chatTextView,line])
        userHeader.snp.makeConstraints { make in
//            make.top.equalTo(16.0)
            make.bottom.equalTo(chatTextView.snp.bottom)
            make.right.equalTo(-16.0)
            make.width.height.equalTo(40.0)
        }
        chatTextView.snp.makeConstraints { make in
            make.right.equalTo(userHeader.snp.left).offset(-12.0)
            make.top.equalTo(16.0)
            make.left.equalTo(20.0).priority(690)
        }
        line.snp.makeConstraints { make in
            make.centerX.width.bottom.equalToSuperview()
            make.height.equalTo(0).priority(.high)
            make.top.equalTo(chatTextView.snp.bottom).offset(4.0)
        }
    }
}
